package com.ruoyi;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.info.GitProperties;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;

import com.cyl.wechat.WechatPayData;
import com.ruoyi.livesass.api.sync.LiveActivityDataSynService;

import cn.hutool.core.date.DateTime;

/**
 * 启动程序
 *
 * @author ruoyi
 */
@Configuration(proxyBeanMethods = false)
@ServletComponentScan("com.cyl.yeepay.gateway")
@SpringBootApplication(
        exclude = {DataSourceAutoConfiguration.class},
        scanBasePackages = {"com.ruoyi", "com.cyl"}
)
@EnableConfigurationProperties(WechatPayData.class)
@EnableScheduling
public class RuoYiApplication {
	
	private static final Logger LOG = LoggerFactory.getLogger(LiveActivityDataSynService.class);
	
    public static void main(String[] args) {
        // System.setProperty("spring.devtools.restart.enabled", "false");
    	System.out.println("当前Jar工作目录: " + System.getProperty("user.dir"));
    	ConfigurableApplicationContext context = SpringApplication.run(RuoYiApplication.class, args);
    	System.out.println("服务器启动完成["+DateTime.now().toString()+"]");
    	System.out.println("当前版本信息:");
        RuoYiApplication.printGitInfo(context);

        
//        try {
//            new NettyServer(12345).start();
//            System.out.println("https://blog.csdn.net/moshowgame");
//            System.out.println("http://127.0.0.1:6688/netty-websocket/index");
//        }catch(Exception e) {
//            System.out.println("NettyServerError:"+e.getMessage());
//        }
    }
    
    
    /**
     * 输出运行版本
     *
     * @param context SpringBoot 上下文信息
     */
    private static void printGitInfo(ConfigurableApplicationContext context) {
        try {
        	GitProperties gitProperties = context.getBean(GitProperties.class);
        	System.out.println("Git branch: " + gitProperties.get("branch") );
        	System.out.println("Git build time:  " + gitProperties.get("build.time") );
        	System.out.println("Git commit id " + gitProperties.get("commit.id.full") );
        	System.out.println("Git commit user: " + gitProperties.get("commit.user.name") );
        	System.out.println("Git commit time: " + gitProperties.get("commit.time") );
        	System.out.println("Git commit message: " + gitProperties.get("commit.message.full") );
        } catch (NoSuchBeanDefinitionException e) {
        	e.printStackTrace();
        	LOG.warn(e.getMessage());
        }
    }
    
    
    @Bean
    public TaskScheduler taskScheduler() {
        return new ThreadPoolTaskScheduler();
    }
    
}
